import socket
from urllib import parse,request
import json

HOST, PORT = '', 8888

listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST, PORT))
listen_socket.listen(1)
print('Serving HTTP on port %s ...' , PORT)
while True:
  client_connection, client_address = listen_socket.accept()
  r = client_connection.recv(1024)
  print(r)

  textmod={"encryptedAttentance": "5BCBA99059B900FDED28ABDDDB19C288F09245B625D3677B0F17554160950623276FBA6A76B959D3946D0CFDFFD4AB5B1E907D84CAA2B4C7D9135B0EE24BABD950897D3E4F0D5A2EDD55366A6FD72F3F56A21CF4BCA8BD912E75BDE59615C91FFF8F448729D4D6EB78FDFE4356E08A26956B79835846A7BD8767622C3E90B86B147159F309E70EF47C19FE18301E8BA0E20F590606D9D65520C833F19DE44AC8FBFB8CFAB69E402D9D09B2AE29AF23E37D74EA2D063AC7DBA4661C4864826F2D4A8433A46E33578F116508AF0F4BBDCBA0C505D952BAAE97E2857DEEEAC20DA31549D439F1779147C9290DD6D79718251C9130C26CC6CE8FE2246F1FDA987B72AD59050D147B4D0AB448CA02D0CF48320140683A21F4D8AD1F5F5280B6467A34E48F54BCEF0BF616E570823126CE383C726FA53BAB7B9B90A039767B5C8B600018A567DA795123B51F3F7B18D4210A92EBB52FB7CBD72AB7E7C064549DEBA81EF78D134D45EAEEA7F72A1573B1D6DA74C05C1D8E0DE5566332622EA4594C60E1C4D7F6196F3911119C1DE5CD258232A4998F2D1074D668E22FC2D6D0ECE133B0829A129D27BCD186783A9C14FC29E888","language":"zhs"}
  #json串数据使用
  #textmod = json.dumps(textmod).encode(encoding='utf-8')
  #普通数据使用
  textmod = parse.urlencode(textmod).encode(encoding='utf-8')
  print(textmod)
  #输出内容:b'{"params": {"user": "admin", "password": "zabbix"}, "auth": null, "method": "user.login", "jsonrpc": "2.0", "id": 1}'
  header_dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko',"accesstoken":"IHbFDAI4GOIGc24cGJqMdbwrMUyKzkyhxWKDlBlgrhb8QaFBEiw9YzSd6olwjZcUXtiXgUfrsQOygGR044DN/VA9DAaIW8X/qj2Y2St7utENcca+6QeAQHTQQMm+1LJQaOD6yXx+lAgDDN2sbPAnBxcVEhzAjjXYpCBo/uhu+dE="}
  url='https://daka.citycloud.com.cn:58889/ncchr/attentance/encryptSignIn?clientV=2-7.1.2-1-1&token=gray6326-2d71-4732-898f-uspacemobile__4eaf44bd0e614dae29a13c505c1e83e3_1674956644563dccore0yonbip-ec-base0bd29521YT_a5zdldng'
  req = request.Request(url=url,data=textmod,headers=header_dict,method="POST")
  res = request.urlopen(req)
  res = res.read()
  print(res)
  #输出内容:b'{"jsonrpc":"2.0","result":"37d991fd583e91a0cfae6142d8d59d7e","id":1}'
  print(res.decode(encoding='utf-8'))

  http_response = ("""\
  HTTP/1.1 200 OK

  """+res.decode(encoding='utf-8') ).encode("utf-8")

  client_connection.sendall(http_response)
  client_connection.close()
